"use strict";
/* Controllers */
app.controller("dpExecuteLogDetailController", ['$scope', '$location', '$rootScope', '$routeParams', 'dpExecuteLogDetailService', function ($scope, $location, $rootScope, $routeParams, dpExecuteLogDetailService) {

    var vm = $scope.vm;

    vm.p = {};
    vm.result = {};
    vm.p.uniqueId = $routeParams.uniqueId;

    var errorFn = function (result) {
        alert(result);
    };

    $scope.getDetail = function () {
        var vm = $scope.vm;
        var params = $scope.vm.p;
        var procFn = function (response) {
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            // 填充属性
            $("#startTime").val(data.startTime);
            $("#runTime").val((data.runTime/60).toFixed(2));
            $("#sql").val(data.querySql);
        };
        dpExecuteLogDetailService.findOneByUniqueId(params, procFn, errorFn);
    };

    $scope.formatSql = function(sql){
        return window.sqlFormatter.format(sql, {
          language: 'hive',
          tabWidth: 2,
          keywordCase: 'upper',
          linesBetweenQueries: 2
        })
    }
    $scope.getDetail();

}]);


/* Services */
app.service('dpExecuteLogDetailService', ['ajaxService', function (ajaxService) {

    this.findOneByUniqueId = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dp_execute_log/findOneByUniqueId.do", successFunction, errorFunction);
    };


}]);
